import { Entity, Column, ManyToOne, JoinColumn, CreateDateColumn } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { Tag } from './tag.entity';
import { Content } from '../../contents/entities/content.entity';

@Entity('content_tag_mapping')
export class ContentTagMapping {
  @ApiProperty({
    format: 'uuid',
    description: '内容的唯一标识',
  })
  @Column('uuid', { primary: true, name: 'content_id' })
  contentId: string;

  @ApiProperty({
    format: 'uuid',
    description: '标签的唯一标识',
  })
  @Column('uuid', { primary: true, name: 'tag_id' })
  tagId: string;

  @ApiProperty({
    format: 'date-time',
    description: '映射关系的创建时间',
  })
  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;

  @ManyToOne(() => Content, { createForeignKeyConstraints: false })
  @JoinColumn({ name: 'content_id' })
  content: Content;

  @ManyToOne(() => Tag, (tag) => tag.contentMappings, { createForeignKeyConstraints: false })
  @JoinColumn({ name: 'tag_id' })
  tag: Tag;
}
